//
//  XYJLXResultFrameModel.m
//  徙游记-01
//
//  Created by hcios on 2017/7/13.
//  Copyright © 2017年 鹿林. All rights reserved.
//

#import "XYJLXResultFrameModel.h"

#define TitleFont [UIFont systemFontOfSize:15]
#define ContextFont [UIFont systemFontOfSize:13]

@implementation XYJLXResultFrameModel

-(void)setModel:(XYJLXResultModel *)model{
    _model = model;
    CGFloat padding = 10;
    
    
    //文本
    if ([model.comment_description isEqualToString:@""]) {
        self.commentFrame = CGRectZero;
    }else{
        CGSize commentSize = [self sizeWithText:model.comment_description font:ContextFont maxSize:CGSizeMake(SCREEN_WIDTH - padding * 2, MAXFLOAT)];
        CGFloat commentW = commentSize.width;
        CGFloat commentH = commentSize.height;
        self.commentFrame = RECT_MAKE(padding, padding, commentW, commentH);
    }
    //图片
    if (model.imageUrlArray.count == 0) {
        self.scrollFrame = RECT_MAKE(padding, CGRectGetMaxY(self.commentFrame)+5, 0, 0);
    }else{
        self.scrollFrame = RECT_MAKE(padding, CGRectGetMaxY(self.commentFrame)+5, SCREEN_WIDTH - padding, 100);
    }
    //底部信息
    if ([model.user_name isEqualToString:@""]) {
        self.userFrame = RECT_MAKE(padding, CGRectGetMaxY(self.scrollFrame)+5, 0, 0);
    }else{
        
        self.userFrame = RECT_MAKE(padding, CGRectGetMaxY(self.scrollFrame)+5, SCREEN_WIDTH / 2, 20);
        self.dayFrame = RECT_MAKE(SCREEN_WIDTH / 2, CGRectGetMaxY(self.scrollFrame)+5, SCREEN_WIDTH / 2 - padding, 20);
    }
    
    _cellHeight = CGRectGetMaxY(self.userFrame) + padding;
}

-(CGSize)sizeWithText:(NSString *)text font:(UIFont *)font maxSize:(CGSize)maxSize
{
    NSDictionary *dict = @{NSFontAttributeName : font};
    return [text boundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOrigin attributes:dict context:nil].size;
}
@end
